﻿using LoveEatRabbit.API.Read.Applications.Commands.Users;
using LoveEatRabbit.Domain.RBAC;
using LoveEatRabbit.ErrorCode;
using LoveEatRabbit.Infrastructure.Interfaces;
using MediatR;

namespace LoveEatRabbit.API.Read.Applications.CommandHandlers.Users
{
    public class UserGetQueryCommandHandler : IRequestHandler<UserGetQueryCommand, APIResult<List<UserModel>>>
    {
        private readonly IBaseRespository<UserModel> userRep;

        public UserGetQueryCommandHandler(IBaseRespository<UserModel> userRep)
        {
            this.userRep = userRep;
        }

        public Task<APIResult<List<UserModel>>> Handle(UserGetQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<UserModel>> result= new APIResult<List<UserModel>>();    
            result.Code=APIResultCode.查询成功;
            result.Message=APIResultCode.查询成功.ToString();


            var res=userRep.GetAll().ToList();
            if (res != null)
            {
                res=res.Where(x=>x.UserId==request.UserId).ToList();
            }
            result.Data= res;



            return Task.FromResult(result);
        }
    }
}
